/*** 
 * @Date: 2020-07-09 18:10:59
 * @LastEditors: leehave
 * @LastEditTime: 2020-09-05 15:47:08
 */
/*** 
 * @Date: 2020-07-09 18:10:59
 * @LastEditors: leehave
 * @LastEditTime: 2020-08-13 10:05:58
 */
import qs from 'qs'
import request from '@/utils/request'
import store from '@/store'
import { PORT } from './api'
import axios from 'axios'
import { objectConvertToQuery } from '@/utils/index'
/**
 * 登录接口请求token与userinfo
 * @param params {code: code}
 */
export function loginByCode(params = {}) {
  
  return request({
    url: PORT.login,
    method: 'post',
    data: qs.stringify(params)
  })
}
/**
 * 获取登录用户信息
 * @param params
 */
export function getUserInfo(params = {}) {
  
  return request({
    url: PORT.userInfo,
    method: 'get',
    data: params
  })
}

/**
 * 支付
 */
export function openPayment(params = {}){
  
  return request({
    url: PORT.payment,
    method: 'post',
    data: qs.stringify(params)
  })
}

/**
 * 判断用户是否关注
 */
export function authSubscribe(params = {}){
  
  return request({
    url: PORT.subscribe,
    method: 'post',
    data: qs.stringify(params)
  })
}
/**
 * 绑定用户手机号
 * @fuction bindUserPhone
 */
export function bindUserPhone(params = {}){
 
  return request({
    url: PORT.bindPhone,
    method: 'put',
    data: qs.stringify(params)
  })
}

/**
 * 获取微信jssdk
 */
export function getJssdk(url){
  
  return request({
    url: PORT.getJsdk + '?url=' + url,
    method: 'get',
  })
}
/**
 * 更新用户手机号
 * @function updatePhoneService
 */
export function updatePhoneService(params = {}){
 
  return request({
    url: PORT.updateUserInfo,
    method: 'post',
    data: qs.stringify(params)
  })
}

/**
 * 发送验证码
 * @function sendMessageService
 * @params {tel,type}
 */
export function sendMessageService(params = {}){
  return request({
    url: PORT.sendCode,
    method: 'post',
    data: qs.stringify(params)
  })
}
/**
 * 修改用户信息
 * @function updateUserInfoService
 * @params {realname, username}
 */
export function updateUserInfoService(params = {}){
  return request({
    url: PORT.updateUserInfo,
    method: 'put',
    data: qs.stringify(params)
  })
}
/**
 * 新闻列表
 * @function newsInfoService
 * @params {catid, page}
 */
export function newsInfoService(params = {}){
  let url = objectConvertToQuery(params)
  return request({
    url: PORT.article + url,
    method: 'get',
    data: params
  })
}
/**
 * 新闻详情
 * @function newsDetailService
 * @params {id}
 */
export function newsDetailService(id){
  return request({
    url: `${PORT.article}/${id}`,
    method: 'get',
    data: id
  })
}

/**
 * 医院简介
 * @function introduceService
 * @params {id}
 */
export function introduceService(id){
  return request({
    url: `${PORT.intro}/${id}`,
    method: 'get',
    data: id
  })
}
/**
 * 通知公告navlist
 * @function introduceService
 * @params {id}
 */
export function tongzhiListService(id){
  return request({
    url: `${PORT.intro}/nav`,
    method: 'get',
    data: id
  })
}
/**
 * 广告位
 * @function bannerService
 * @params {poster}
 */
export function bannerService(poster){
  return request({
    url: `${PORT.banner}/${poster}?expand=poster`,
    method: 'get',
    data: poster
  })
}

/**
 * 附件上传
 * @function uploadService
 * @params {files}
 */
export function uploadService(files){
  return request({
    url: PORT.upload,
    method: 'post',
    data: files
  })
}

/**
 * 反馈
 * @function feedbackService
 * @params {type,content,picurl,tel,name}
 */
export function feedbackService(params = {}){
  return request({
    url: PORT.feedback,
    method: 'post',
    data: qs.stringify(params)
  })
}
/**
 * 反馈选项
 * @function feedbackOptionService
 */
export function feedbackOptionService(){
  return request({
    url: PORT.feedbackOption,
    method: 'get',
  })
}

/**
 * 我的地址列表
 */
export function myAddress(){
  return request({
    url: PORT.address,
    method: 'get',
  })
}
/**
 * 添加地址
 */
export function addAddressService(params){
  return request({
    url: PORT.address,
    method: 'post',
    data: qs.stringify(params)
  })
}

/**
 * 修改地址
 */
export function putAddressService(params,id){
  return request({
    url: PORT.address + '/' + id,
    method: 'put',
    data: qs.stringify(params)
  })
}
/**
 * 删除地址
 */
export function delAddressService(id){
  return request({
    url: PORT.address + '/' + id,
    method: 'delete',
  })
}
/**
 * 查看地址
 */
export function queryAddressService(id){
  return request({
    url: PORT.address + '/' + id,
    method: 'get',
  })
}

/**
 * 验证旧手机号
 */
 export function checkOldTel(params){
  return request({
    url: PORT.checkOldPhone,
    method: 'put',
    data: qs.stringify(params)
  })
}
/**
 * 验证新手机号
 */
 export function checkNewTel(params){
  return request({
    url: PORT.changeTel,
    method: 'put',
    data: qs.stringify(params)
  })
}

/**
 * 选择服务时间
 * @params {check_id}
 */
 export function nurseDateSelectServer(params = {}){
  let url = objectConvertToQuery(params)
  return request({
    url: PORT.nurseDateOption + url,
    method: 'get',
    data: params
  })
}